/**
 * 
 */
package info.guerrero.cartaalta;

import java.util.ArrayList;
import android.content.Context;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


/**
 * @author pablo_guerrero
 *
 */
public class AdapterListPlayers extends BaseAdapter{
	private Context context;
	protected Activity activity;
	protected ArrayList<Player> playerList;
	private LayoutInflater inflater;
	
	public AdapterListPlayers(Activity activity, ArrayList<Player> playerz) {
		super();
	    this.activity = activity;
	    this.playerList = playerz;
	  }

	@Override
		public int getCount() {
		return playerList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return playerList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return playerList.get(position).getNumJug();
	}

	@Override
	public View getView(int position, View convertview, ViewGroup parent) {
		 View view = convertview;
	        if(convertview == null){
	            LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	            view = inflater.inflate(R.layout.player,null);
	        }
	        
	        Player myPlayer = playerList.get(position);
	        Log.d("PELLODEBUG", myPlayer.toString());
	         
	        TextView textViewTitle = (TextView) view.findViewById(R.id.textViewNumbPlayer);
	        textViewTitle.setText(myPlayer.getNumJug());
	        ImageView myImageView = (ImageView) view.findViewById(R.id.imageViewCard);
			Bitmap myBitmap = (BitmapFactory.decodeResource(activity.getResources(),activity.getResources().getIdentifier("myImageView","drawable", "info.guerrero.cartaalta")));
	        myImageView.setImageBitmap(myBitmap);
	       
	        return view;
		
	}


}
